import java.sql.*;

/**
 * @author xxx
 * @date 2021/1/3 0:58
 * @description
 */
public class Test {
    public static void main(String[] args) throws ClassNotFoundException, SQLException {
        //1.获取驱动字节码对象D:\java349\day18\lib\mysql-connector-java-5.1.37-bin.jar!\com\mysql\jdbc\Driver.class
        Class.forName("com.mysql.jdbc.Driver");

        //2. Connection 获取定义数据库地址和用户密码连接到数据库
        String url="jdbc:mysql://localhost:3306/day18";
        String password="root";
        String user="root";
        Connection connection= DriverManager.getConnection(url,user,password);
        //3.Statement调用sql对象
        Statement statement=connection.createStatement();
        String sql="SELECT * FROM scores";

        ResultSet resultSet=statement.executeQuery(sql);

        //执行sql语句查询score表,获取结果集ResultSet

        while (resultSet.next()){
            Integer sid =resultSet.getInt(1);
            Integer score=resultSet.getInt(2);
            String  sname=resultSet.getString(3);

            System.out.println("编号: "+sid+", 姓名: "+sname+", 成绩: "+score);
        }

         connection.close();
         statement.close();
         resultSet.close();
    }
}
